#!/usr/bin/env node

const path = require('path')
const fs = require('fs')
const inquirer = require('inquirer')
const ejs = require('ejs')

inquirer
  .prompt([
    {
      type: 'input',
      name: 'name',
      message: 'Project name?'
    }
  ])
  .then(value => {
    const tempDir = path.resolve(__dirname, 'templates')
    const destDir = process.cwd()

    fs.readdir(tempDir, (err, files) => {
      if (err) throw err

      files.forEach(file => {
        ejs.renderFile(path.resolve(tempDir, file), value, (err, result) => {
          if (err) throw err

          fs.writeFileSync(path.resolve(destDir, file), result)
        })
      })
    })
  })
